import request from '@/utils/request'

// 获取字典类型列表
export function getDictTypes(params) {
  return request({
    url: '/api/DictType',
    method: 'get',
    params
  })
}

// 获取单个字典类型详情
export function getDictTypeById(id) {
  return request({
    url: `/api/DictType/${id}`,
    method: 'get'
  })
}

// 新增字典类型
export function addDictType(data) {
  return request({
    url: '/api/DictType',
    method: 'post',
    data
  })
}

// 修改字典类型
export function updateDictType(data) {
  return request({
    url: `/api/DictType/${data.dictId}`,
    method: 'put',
    data
  })
}

// 删除字典类型
export function deleteDictType(id) {
  return request({
    url: `/api/DictType/${id}`,
    method: 'delete'
  })
}

// 批量删除字典类型
export function batchDeleteDictType(ids) {
  return request({
    url: '/api/DictType/batch',
    method: 'delete',
    data: ids
  })
}

// 根据字典类型获取字典数据
export function getDictDataByType(dictType) {
  return request({
    url: `/api/Dict/data/${dictType}`,
    method: 'get'
  })
}

// 获取字典选项
export function getDictOptions(dictType) {
  return request({
    url: `/api/Dict/options/${dictType}`,
    method: 'get'
  })
}

// 批量获取字典选项
export function getMultipleDictOptions(dictTypes) {
  return request({
    url: '/api/Dict/options/batch',
    method: 'post',
    data: dictTypes
  })
}

// 刷新缓存
export function refreshCache() {
  return request({
    url: '/api/Dict/refresh-cache',  
    method: 'post'
  })
}

// ========== 字典数据相关 API ==========

// 获取字典数据列表
export function getDictDataList(params) {
  return request({
    url: '/api/DictData',
    method: 'get',
    params
  })
}

// 获取单个字典数据详情
export function getDictDataById(id) {
  return request({
    url: `/api/DictData/${id}`,
    method: 'get'
  })
}

// 新增字典数据
export function addDictData(data) {
  return request({
    url: '/api/DictData',
    method: 'post',
    data
  })
}

// 修改字典数据
export function updateDictData(data) {
  return request({
    url: `/api/DictData/${data.dictCode}`,
    method: 'put',
    data
  })
}

// 删除字典数据
export function deleteDictData(id) {
  return request({
    url: `/api/DictData/${id}`,
    method: 'delete'
  })
}